package com.heima.controller;


import com.heima.pojo.TbNode;
import com.heima.pojo.dto.TbNodeDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.TbBusinessVo;
import com.heima.pojo.vo.TbNodeSearchVo;
import com.heima.pojo.vo.TbVendingMachineVo;
import com.heima.service.ITbNodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 点位表 前端控制器
 * </p>
 *
 * @author AkiRinko
 * @since 2024-06-08
 */
@RestController
@RequestMapping("/api/vm-service/node")
@RequiredArgsConstructor
public class TbNodeController {
    private final ITbNodeService tbNodeService;

    /**
     * 点位搜索/区域详情
     *
     * @param pageIndex
     * @param pageSize
     * @param name
     * @param regionId
     * @return
     */
    @GetMapping("/search")
    private PageResponse<TbNodeSearchVo> selectNodePage(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                                        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                        @RequestParam(value = "name", required = false) String name,
                                                        @RequestParam(value = "regionId", required = false) String regionId) {
        return tbNodeService.selectNodePage(pageIndex, pageSize, name, regionId);
    }

    /**
     * 新增点位
     *
     * @param tbNodeDto
     */
    @PostMapping
    private void insertNode(@RequestBody TbNodeDto tbNodeDto) {
        tbNodeService.insertNode(tbNodeDto);
    }

    /**
     * 获取点位详情
     *
     * @param nodeId
     * @return
     */
    @GetMapping("/vmList/{nodeId}")
    private List<TbVendingMachineVo> selectVmList(@PathVariable String nodeId) {
        return tbNodeService.selectVMList(nodeId);
    }

    /**
     * 修改点位
     *
     * @param nodeId
     * @param dto
     */
    @PutMapping("/{nodeId}")
    private void updateNode(@PathVariable String nodeId,
                            @RequestBody TbNodeDto dto) {
        tbNodeService.updateNode(nodeId, dto);
    }

    /**
     * 删除点位
     *
     * @param nodeId
     */
    @DeleteMapping("/{nodeId}")
    private void deleteNode(@PathVariable String nodeId) {
        tbNodeService.deleteNode(nodeId);
    }

    /**
     * 点位数量
     * @return
     */
    @GetMapping("/count")
    private Integer nodeCount() {
        return tbNodeService.nodeCount();
    }

}
